using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace P4Shelf
{
    public partial class Form1 : Form
    {
        private Nutils.ShelfGUI _ShelfGUI;
        private Nutils.Helper _Helper;
        private RenameDialog _RenameDialog;
        private Splash _LoadupSplash;

        public Form1()
        {
            // -- Toss up a splash screen
            //...
            //_LoadupSplash = new Splash(this);
            InitializeComponent();
            //this.timer1.Start();
        }


        private void Form1_Load(object sender, EventArgs e)
        {
            // -- Create Impls, Mgrs, Tracers, etc.
            Nutils.Console.AddTimeStampedStringTrace(SetConsoleWindowString, Nutils.Console.Levels.NOTIFY | Nutils.Console.Levels.ERROR);
            Nutils.Console.AddFileTrace("log.txt", true, Nutils.Console.Levels.ALL);

            _Helper = new Nutils.Helper("help.xml", SetToolTip, this.components);
            _ShelfGUI = new Nutils.ShelfGUI();
            _ShelfGUI.Connect();
            if (!_ShelfGUI.Connected)
            {
                this.tabControl1.SelectedIndex = 2;
            }

            // -- Configure Controls
            _Create_Globals();
            _Create_CreateTab();
            _Create_ManageTab();
            _Create_ConfigTab();
        }

        private void _Create_Globals()
        {
            //text_console_scrollbar.Value = text_console_scrollbar.Maximum;
            this._Helper.RegisterControl(tabControl1.TabPages[3]);
            this._Helper.RegisterControl(text_console);
            this.label_about.Text = this._Helper.About;
        }

        public void SetToolTip(string s)
        {
            this.toolStripStatusLabel1.Text = s;
        }

        public void SetConsoleWindowString(string ErrorMsg)
        {
            this.text_console.Text += ErrorMsg + "\n";
            //text_console_scrollbar.Value = text_console_scrollbar.Maximum;
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (null == _LoadupSplash)
                return;

            _LoadupSplash.Close();
            _LoadupSplash = null;
            this.SetTopLevel(true);
        }

        private void quickSyncToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this._ShelfGUI.QuickSync();
        }
    }
}